package com.hongshan.wallet.core.wallet

import android.arch.lifecycle.Observer
import android.arch.lifecycle.ViewModelProviders
import android.databinding.ViewDataBinding
import android.os.Bundle
import com.alibaba.android.arouter.facade.annotation.Route
import com.hongshan.wallet.BR
import com.hongshan.wallet.R
import com.hongshan.wallet.base.MyActivity
import com.hongshan.wallet.core.InputPwdDialogFragment
import com.hongshan.wallet.router.RouterIndex
import kotlinx.android.synthetic.main.appbar.*

/**
 * Copyright Zhangxx.
 * Copyright (c) 2019
 * All rights reserved
 *
 * @project  : Wallet
 * @package  : com.example.wallet.core.home
 * @author   : zhangxx
 * @date     : 2019/3/27
 * @email    : qq957413212@hotmail.com
 * @desc     : //TUDO
 */

@Route(path = RouterIndex.BALANCE_INTO)
class IntoBalanceActivity : MyActivity<ViewDataBinding, IntoBalanceViewModel>() {

    val inputPwdDialogFragment by lazy { InputPwdDialogFragment() }

    override fun initVariableId() = BR.vm

    override fun initContentView(savedInstanceState: Bundle?) = R.layout.activity_balance_into

    override fun initViewModel() = ViewModelProviders.of(this)[IntoBalanceViewModel::class.java]

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        tvTitle.text = "转入余额"
        inputPwdDialogFragment.action = "转入余额"
        inputPwdDialogFragment.inputComplete = {
            viewModel.checkPwd(it)
        }
        viewModel.showPwdDialog.observe(this, Observer {
            inputPwdDialogFragment.money = "￥${viewModel.money.get() ?: "0"}"
            inputPwdDialogFragment.show(supportFragmentManager, javaClass.name)
        })
        viewModel.hidePwdDialog.observe(this, Observer {
            inputPwdDialogFragment.dismiss()
        })
    }
}